/*
 * BlockTile.java
 *
 * Created on 22. Dezember 2006, 21:03
 *
 * Copyright (c) 2007 Daniel Gronau
 *
 * This file is part of KanjiTori.
 *
 * KanjiTori is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * KanjiTori is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

package kanjitori.map.tile;

import com.jme.math.Vector3f;
import com.jme.scene.TriMesh;
import com.jme.scene.shape.Box;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Pirx
 */
public class BlockTile extends AbstractTile {
    
    private static final String RENDERSTATE = "renderstate";
    private static final String LOW = "low";
    private static final String HIGH = "high";
    
    private String renderstate;
    private float low;
    private float high;
    private Box block;
    
    /** Creates a new instance of BlockTile 
     * @param name 
     * @param ref 
     * @param renderstate 
     * @param low 
     * @param high 
     */
    public BlockTile(String name, char ref, String renderstate, float low, float high) {
        super(name, ref);
        this.renderstate = renderstate;
        this.low = low;
        this.high = high;
    }
    
    public BlockTile(String name, char ref, String renderstate, float high) {
        super(name, ref);
        this.renderstate = renderstate;
        this.low = -1;
        this.high = high;
    }
    
    public BlockTile() {
    }
    
    public void init() {
        block = new Box("block", new Vector3f(-1, low, -1), new Vector3f(1, high, 1));
    }

    public void setParams(Map<String, String> map) {
        renderstate = map.get(RENDERSTATE);
        low = Float.parseFloat(map.get(LOW));
        high = Float.parseFloat(map.get(HIGH));
    }

    public Map<String, String> getParams() {
        Map<String, String> map = new HashMap<String, String>();
        map.put(RENDERSTATE, renderstate);
        map.put(LOW, "" + low);
        map.put(HIGH, "" + high);
        return map;
    }    

    public TriMesh getMesh(int index) { 
        if (block == null) {
            init();
        }
        return block;
    }

    public int getSize() {
        return 1;
    }

    public String getRenderStateName(int index) {
        return renderstate;
    }
    
}
